import request from '../utils/request';



const CloudUrl:string = 'http://101.34.56.158:9421/api/v1';
// const CloudUrl:string = 'http://127.0.0.1:9421/api/v1';
//测试分页接口
export const fetchPageTest = (query: any) => {
    console.log("here")
    console.log(query)
    return request({
        url: 'http://localhost:9001/userController/getUserPage',
        method: 'get',
        params:{
            pageNo:query.pageIndex,
            pageSize:query.pageSize
        }
    });
};
// 用户分页
export const fetchPage = (query: any) => {
    console.log("here")
    console.log(query)
    return request({
        url: CloudUrl+'/user/pages',
        method: 'get',
        params:{
            pageNo:query.pageIndex,
            pageSize:query.pageSize,
            name:query.name
        }
    });
};

//书籍管理
export const BookPage = (no:string,size:string) =>{
    return request({
        url:CloudUrl + "/book/pages",
        method:"get",
        params:{
            pageNo:no,
            pageSize:size
        }
    })
}
//统计数量
export const fetchCount = () =>{
    return request({
        url:CloudUrl+'/count',
        method:'get',
    })
}
//修改密码
export const changePassword = (name:string|null,form:any) =>{
    if (form.old.length === 0 || form.new.length === 0 || name === null){
        return Promise.reject("密码不能为空")
    }
    return request({
        url:CloudUrl+'/admin/change',
        method:'post',
        data:{
            username:name,
            old:form.old,
            new:form.new
        }
    })
}
//登录
export const adminLogin = (username:string,password:string) =>{
    return request({
        url:CloudUrl+'/admin/login',
        method:'post',
        data:{
            username:username,
            password:password
        }
    })
}
//书籍数据
export const BookStatic = () =>{
    return request({
        url:CloudUrl + '/static',
        method:"get",
    })
}
//图书阅读量rank
export const BookRank = () =>{
    return request({
        url:CloudUrl + '/book/rank',
        method:"get"
    })
}
// 当前ip地址
export const CurIp = ()=>{
    return request({
        url:"https://ip.useragentinfo.com/json",
        method:"get",
    })
}
//TODOlist
//获取todolist
export const GetToDoList = () =>{
    return request({
        url:CloudUrl + "/todo/get",
        method:"get"
    })
}
//修改todolist状态
export const changeToDoList = (id:string) =>{
    return request({
        url:CloudUrl + "/todo/set",
        method:"get",
        params:{
            id:id
        }
    })
}
//删除todolist
export const DelTodo = (id:string) =>{
    return request({
        url:CloudUrl + "/todo/del",
        method:"post",
        data:{
            id:id
        }
    })
}
//新增todo
export const AddTodo = (title:string):any =>{
    return request({
        url:CloudUrl + "/todo/add",
        method:"post",
        data:{
            title:title
        }
    })
}

//修改用户姓名
export const ChangeUserName = (id:string, username:string) =>{
    return request({
        url:CloudUrl + "/user/changename",
        method:"get",
        params:{
            id:id,
            username:username
        }

    })
}
//删除用户
export const DelUser = (id:string) =>{
    return request({
        url:CloudUrl + "/user/del",
        method:"delete",
        params:{
            id:id
        }
    })
}

export const BooKALL = () => {
    return request({
        url:CloudUrl + "/book/all",
        method:"get",
    })
}